package com.gitee.ywj1352.bootstrap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wenjie.yang on 2019/7/18.
 */
@EnableAutoConfiguration
@RestController
public class SpringbootApplicationBootstrap {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext anContext = new AnnotationConfigApplicationContext();
        anContext.setId("杨文杰");
        //在杨文杰上下文里 注册一个 bean 给 服务上下文
        anContext.registerBean("helloWord",String.class,"hello");
        anContext.refresh();

        //类比于 Spring Mvc Root WebApplication 和 DispatcherServlet webApplication
        //DispatcherServlet webApplication parent = Root Web Application
        new SpringApplicationBuilder(SpringbootApplicationBootstrap.class)
                .parent(anContext)//显式地设置双亲上下文
                .run(args);
    }

    @Autowired
    @Qualifier("helloWord")
    private String hello;

    @GetMapping("/hi")
    public String hi(){
        return hello;
    }


}
